// pages/adminProduction/adminProduction.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    mycurrent: '待采购',
    list: [],

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.getlist()
  },
  MyonChange(e) {
    this.setData({
      mycurrent: e.detail.key,
    })
    if (e.detail.key == '账号管理') {
      this.userList()
    } else {
      this.getlist()
    }
  },
  getlist: function() {
    var that = this
    wx.request({
      url: app.globalData.api + 'productionOrderForm/list',
      data: {
        "keyword": "",
        "orderBy": "",
        "status": this.data.mycurrent,
        "businessManagerId": "",
        "timeRange": "",
        "page": "",
        "rows": 99
      },
      header: {
        Authorization: wx.getStorageSync('token')
      },
      method: 'POST',
      success: function(res) {
        console.log(res)
        if (res.data.code == 200) {
          that.setData({
            list: res.data.data.productionOrderFormList
          })
        } else {
          that.setData({
            list: []
          })
        }
      }
    })
  },

  // userList: function() {
  //   var that = this
  //   wx.request({
  //     url: app.globalData.api + 'user/list',
  //     data: {
  //       page: 1,
  //       rows: 999,
  //       roleName: '产品经理'
  //     },
  //     method: 'POST',
  //     header: {
  //       Authorization: wx.getStorageSync('token')
  //     },
  //     success: function(res) {
  //       console.log(res)
  //       if (res.data.code == 200) {
  //         that.setData({
  //           uList: res.data.data.userList
  //         })
  //       }else{
  //         that.setData({
  //           uList: []
  //         })
  //       }
  //     }
  //   })
  // },
  deleUser: function(e) {
    var that = this
    wx.showModal({
      title: '提示',
      content: '确认删除?',
      success(res) {
        if (res.confirm) {
          wx.request({
            url: app.globalData.api + 'user/' + e.currentTarget.dataset.id,
            data: {},
            header: {
              Authorization: wx.getStorageSync('token')
            },
            method: 'DELETE',
            success: (res) => {
              if (res.data.code == 200) {
                wx.showToast({
                  title: '删除成功',
                })
                that.userList()
              }
            }
          })
        }
      }
    })
  },
  edit: (e) => {
    wx.navigateTo({
      url: '/pages/production_order/production_order?id=' + e.currentTarget.dataset.id
    })
  },
  edlitUser: function(e) {
    wx.navigateTo({
      url: '/pages/account/account?type=产品经理&id=' + e.currentTarget.dataset.id,
    })
  },
  addAccount: function() {
    wx.navigateTo({
      url: '/pages/account/account?type=产品经理'
    })
  },
  goImg(e) {
    wx.request({
      url: app.globalData.api + 'designDiagram/findDesignDiagramStyleNumber/' + e.currentTarget.dataset.imgid,
      data: '',
      header: {
        Authorization: wx.getStorageSync('token')
      },
      success: function (res) {
        if (res.data.code == 200) {
          wx.navigateTo({
            url: '/pages/details/details?id=' + res.data.data.id,
          })
        } else {
          wx.showModal({
            title: '提示',
            content: res.data.errorMsg,
          })
        }

      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    // this.userList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})